CBMSTEVE.CA - Personal pages of Steve J. Gray |
Changes | Info | Prototypes | Remakes | PET Projects | CBM Projects | Modding | 3D Models | KiCad | Github | Ohio Scientific | Other | My Software | My Collections | Facebooks |
PET Keyboards are old and stop functioning properly after a while making cleaning necessary. They get broken, or simply misplaced. The SK model keyboards (8032-SK, 8096-SK, 8296 and 8296D) are especially prone to getting lost due to them being detached. Whatever the reason, an easy simple replacement is sometimes needed. This page will describe one solution I have developed... that of using the VIC/C64 mechanism. Perhaps later other keyboards can be adapted.
The C64 keyboard has the advantage of being very common, plus it is actually plug-compatible to PET motherboards, and is usable with only a little work. This page will describe the replacement of the PET Business Keyboard, and modifying the "EDIT-4-80-B-60Hz.BIN" ROM. The same modifications can be applied to the other EDIT roms with minor tweaking.
The PET keyboards come in THREE basic layouts. The first PETs used a "chicklet-type" keyboard much like calculators at the time. Commodore then replaced those with the normal/graphics "N" keyboard. When the 80-column machines became available, they used the business "B" keyboard. Some of these keyboards also had localized versions (such as german DIN). For the early PET's the keyboards are mounted in the main case and plugged into the motherboard. For later "SK" models they were separate and plugged in via a cable with DB-25 connector.
All PET keyboards work on the same principle. They use a passive 8 x 10 matrix (ROWS and COLS) of keys. When you press a key it makes contact between one ROW and one COLUMN. The PET selects a ROW then reads the COLUMN to see what key (or keys) are pressed.
The PET firmware consists of BASIC, KERNAL, and EDIT ROMS. The EDIT ROMS are responsible for all the screen and keyboard routines. There are versions for different keyboards (graphics/business), screen widths (40/80), and power frequency (50/60). We need to change this ROM. The scanning routine contains a data table of 8x10 = 80 bytes that represents the keyboard matrix. By modifying this table we can support any 8x10 or smaller matrix.
Let's take a look at the Business Keyboard table inside the "901474-04" EDIT ROM:
ADDR ORIGINAL DATA TABLE COL0 COL1 COL2 COL3 COL4 COL5 COL6 COL7 ---- ----------------------- ----- ----- ----- ----- ----- ----- ----- ----- E6D1: 16 04 3A 03 39 36 33 DF ; $$-16 $$-04 : STOP 9 6 3 BARRW | ROW0 E6D9: B1 2F 15 13 4D 20 58 12 ; 1 ^/ $$-15 HOME M SPACE X RVS | ROW1 E6E1: B2 10 0F B0 2C 4E 56 5A ; 2 RPT $$-0F 0 , N V Z | ROW2 E6E9: B3 00 19 AE 2E 42 43 00 ; 3 SHIFT $$-19 . . B C SHIFT | ROW3 E6F1: B4 5D 4F 11 55 54 45 51 ; 4 ] O DOWN U T E Q | ROW4 E6F9: 14 50 49 C0 59 52 57 09 ; DEL P I @ Y R W TAB | ROW5 E701: B6 5B 4C 0D 4A 47 44 41 ; 6 [ L RETRN J G D A | ROW6 E709: B5 5C 4B 3B 48 46 53 9B ; 5 \ K ; H F S ESC | ROW7 E711: B9 06 DE B7 B0 37 34 31 ; 9 $$-06 UARRW 7 0 7 4 1 | ROW8 E719: 05 0E 1D B8 2D 38 35 32 ; $$-05 $$-0E RIGHT 8 - 8 5 2 | ROW9 |
The original data table resides at $E6D1 in the PET's memory map, or offset $06D1 in the ROM itself. The EDIT ROM is 2K in size. The first byte ($16) represents the key in COL0 of ROW0, the second byte ($04) is COL1/ROW0 etc. The bytes are the PETSCII value of the key. This value can be a letter, number, symbol, or control code, or $FF to represent "no key". Look at ROW0/COL3; It's the "RUN/STOP" key. When you press the key a value of $03 is returned, representing the STOP control code. At ROW6/COL7 is $41 for the "A" key, and so on. This assumes you press one key at a time. You can also press SHIFT and a key. The scanning routine will convert the key to the uppercase equivilent as long as the high bit of the value is not set. Setting the high bit marks the key as "un-shiftable".
Notice this table has no $FF codes. Even though the actual keyboard has less than 80 keys, each entry in the table is used. Special codes have been used, in locations where there is no key, that can be accessed by pressing multiple keys. These are marked as "$$-xx", where 'xx' is the control code. Look at ROW9/COL1. It shows "$$-0E" (control code $0E), which on the PET is the code to change the screen to TEXT mode. The only way to access this code is to press three keys at the same time (for example SHIFT+SHIFT+2.
So, now that we understand the keyboard table it's a simple matter of changing these values to match a different keyboard!
The PETs all have the same connector on the motherboard. It's a 20 pin male header with a one pin removed. The connector on the keyboard is "keyed" so that it will connect only one way. The header is labelled with numbers and letters as follows. I have also included a straight numbering of pins for reference, plus the function of each pin:
PET Internal: 12 11 10 9 8 7 6 5 4 3 2 1 J H F E D C B A <-LABEL ON PCB 001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 020 <-PIN GND KEY R9 R8 R7 R6 R5 R4 R3 R2 R1 R0 C7 C6 C5 C4 C3 C2 C1 C0 <-FUNCTION |
You will notice that all ROW pins are grouped as are all COL pins. This is just a convenient way of looking at it. You could just as easily reverse things and say there are 10 columns and 8 rows. The keyboard doesn't care.
The VIC/C64 keyboards are identical. I was initially confused because looking at various documents and data tables show different values for the VIC or C64. It turns out that on the C64 Commodore swapped some lines going between the keyboard connector and the data ports on the I/O chips. That only means that we should ignore the C64 data table (actually it has 4) and use the VIC-20 table. I also found a Commodore mechanical drawing on the web that shows the keyboard, it's matrix, and the wiring diagram for the keyboard.
Let's look at the VIC keyboard and VIC-20 data table:
DATA TABLE IN KERNAL ; KEYSTROKE REPRESENTATION | ROW PIN WIRE CODE -- -- -- -- -- -- -- -- ----- ----- ----- ----- ----- ----- ----- ----- + --- --- ---- ---- 31 33 35 37 39 2B 5C 14 ; 1 3 5 7 9 + POUND DEL | R0 12 BROWN (BR) 5F 57 52 59 49 50 2A 0D ; BARRW W R Y I P * RETRN | R1 11 RED (RD) 04 41 44 47 4A 4C 3B 1D ; CTRL A D G J L ; RIGHT | R2 10 ORANGE (OR) 03 01 58 56 4E 2C 2F 11 ; STOP SHIFT X V N , / DOWN | R3 9 YELLOW (YE) 20 5A 43 42 4D 2E 01 85 ; SPC Z C B M . SHIFT F1 | R4 8 GREEN (GR) 02 53 46 48 4B 3A 3D 86 ; C= S F H K : = F3 | R5 7 BLUE (BL) 51 45 54 55 4F 40 5E 87 ; Q E T U O @ UARRW F5 | R6 6 VIOLET (VI) 32 34 36 38 30 2D 13 88 ; 2 4 6 8 0 - HOME F7 | R7 5 GREY (GY) -- -- -- -- -- -- -- -- ----- ----- ----- ----- ----- ----- ----- ----- | NC 4 COLUMN: C0 C1 C2 C3 C4 C5 C6 C7 | RES 3 BLACK (BK) PIN: 20 19 18 17 16 15 14 13 | KEY 2 WIRE COLOUR: W/BR W/RD W/OR W/YE W/GR W/BL W/VI W/GY | GND 1 WHITE (W) |
The first thing you might notice is that the keyboard only has an 8 by 8 matrix. This could be one reason for the confusing diagrams. It's easy to swap the ROWS and COLUMNS or REVERSE the order of the pins when representing it. The pin numbers and wire colours are from the mechanical document (part# 1001028 REV A). The connector has 20 pins, keyed (pin 2) so that it only goes in one way.
VIC Keyboard: 001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 020 <-PIN GND KEY RES +5V R7 R6 R5 R4 R3 R2 R1 R0 C7 C6 C5 C4 C3 C2 C1 C0 <-FUNCTION |
It turns out that the VIC keyboard has the same basic pinout as the PET keyboard. Since there are two less ROWS, two pins have been re-assigned. One for "RES", the RESTORE key, and one for +5Volts. It should plug right in to the PET with no re-wiring!
Since the VIC keyboard only has an 8 x 8 matrix, there are less keys available for use. Some PET keys such as TAB and ESC aren't found on the VIC keyboard. We will have to re-assign some keys. Also, the VIC has SHIFTED characters that are different, and TWO graphic symbols on most keys, whereas the PET only has one symbol per key. The new data table is here:
ADDR NEW C64 KEYBOARD TABLE COL0 COL1 COL2 COL3 COL4 COL5 COL6 COL7 ---- ----------------------- ----- ----- ----- ----- ----- ----- ----- ----- E6D1: FF FF FF FF FF FF FF FF ; not used | ROW0 E6D9: FF FF FF FF FF FF FF FF ; not used | ROW1 E6E1: 19 13 2D 30 38 36 34 32 ; F7 HOME - 0 8 6 4 2 | ROW2 E6E9: 16 5E 40 4F 55 54 45 51 ; F5 UARRW @ O U T E Q | ROW3 E6F1: 15 3D 3A 4B 48 46 53 9B ; F3 = : K H F S C= | ROW4 E6F9: 0E 00 2E 4D 42 43 5A 20 ; F1 SHIFT . M B C Z SPACE | ROW5 E701: 11 2F 2C 4E 56 58 00 03 ; DOWN / , N V X SHIFT STOP | ROW6 E709: 1D 3B 4C 4A 47 44 41 12 ; RIGHT ; L J G D A CTRL | ROW7 E711: 0D 2A 50 49 59 52 57 DF ; RETRN * P I Y R W BARRW | ROW8 E719: 14 5C 2B 39 37 35 33 31 ; DEL POUND + 9 7 5 3 1 | ROW9 ----- ----- ----- ----- ----- ----- ----- ----- Notes: * Code Change: SHIFT=01 with 00 * Reassign : POUND as \=5C, CTRL as RVS=12, C= as ESC=9B * Reassign : F1 as TEXT=0E, F3 as DELETE LINE=15, F5 as ERASE TO START=16, F7 as SCROLL DOWN=19 |
On the VIC the SHIFT keys have code 01 but on the PET we need 00. The VIC has 4 function keys. The PET, none. We can use these keys for the special PET control codes. Similarly, POUND becomes \, CTRL becomes RVS and C= becomes ESC. Since we are short two ROWS we fill the first 16 bytes with $FF to indicate no key.
The new keyboard mapping is not perfect. We cannot generate some graphics symbols and some SHIFTED keys. In order to properly decode the keyboard it is necessary to re-write some of the PET keyboard scanning routine, which is something that will be left for another time. Also, since we are re-mapping the keys some software that scans the keyboard itself may not function or you may need to find alternate keys to press. As there are less keys, it just won't be possible to activate some of them.
I have provided some replacement ROM images below. You will need a 2Kx8 EPROM of type 2516 or 2716 and an EPROM burner that supports them. I have successfully used an MCUMALL GQ4X with the 2516. These EPROMs will plug directly into the PET motherboard. You may also use a larger capacity EPROM like the 2764 with an appropriate socket adapter.
The ROMs on this page are simple patches of existing Editor ROMs. This works but is limited. I have started a new project to reverse-engineer existing ROMs back into source code that can be re-assembled with any combination of features, including C64 Keyboard matrix, or any other keyboard if desired. I plan to integrate the actual keyboard scanning code from the C64 kernal so that ALL C64 keys, shifted, control and C= keys are supported! You can look at the code on GitHub here: https://github.com/sjgray/cbm-edit-rom. The project page is here.
The SK models require connecting the VIC keyboard to a DB-25 connector to plug into the front of the computer, or building an adapter cable with DB-25 and pin header. The diagram to build an adapter can be found here.
The C64 keyboard will actually fit inside a Business Keyboard PET provided you remove the RESTORE key (see pic at top of page). The cable is very short and the case will only open enough to slide your arm inside to reach the connector. Extending the cable might be an idea. A C128 keyboard would also work since the "main" matrix is identical to the C64/VIC, however the full keyboard is an 8x11 matrix and not all keys on the numeric pad would be accessable. Also, the C128 keyboard will not fit in the PET case. Now that the PET uses the C64/VIC keyboard matrix you could also connect Jim Brain's C=Key adapter and use a PC-type PS/2 keyboard. Actually, you MIGHT be able to use a PC-type keyboard if you REMOVE the controller board and connect wires directly to the keyboard lines. I've never investigated this, although it's possible the matrix is too big to be usable. There are other vintage computers that have simple pasive matrix keyboards that might also be usable, such as the Amiga, Atari ST, Tandy Coco, TI-99 etc...
The PET uses a 74145 4-to-10 line decoder at UC11 to support the 10x8 matrix keyboard. If we replace this chip with a 74154 4-to-16 line decoder we could theoretically support a 16x8 matrix keyboard (128 keys!) including most PC keyboards, C128 keyboard, or even the CBM-II keyboard. We would need to increase the keyboard table to 128 bytes and simply adjust the scanning loop to do 16 rows.
The following are replacement EDIT ROMS. I hope to add additional keyboards in the future.
FILE | COLUMNS | HERTZ | KEYBOARD | NOTES |
edit-4-80-c64-60Hz.bin | 80 | 60Hz | C64/VIC | Ver1. Mostly working. |
edit-4-40-c64hybrid-60Hz.bin | 40 | 60Hz | C64/VIC | Hybrid ROM by 'AZOG' was used as a base, then modified with the new data table. AZOG added support for shifted symbols on top row. 40 col does not support some special codes. |
edit-4-80-c64-50Hz.bin | 80 | 50Hz | C64/VIC | Ver1. Mostly working. |
Created: Jan 25/2013, Last Updated: Aug 16/2025, 4:00pm EST
Send comments or feedback to Steve Gray(sjgray@rogers.com)